package gov.pbc.nn.kjgl.train.view;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.w3c.dom.ls.LSInput;

import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.data.provider.Criteria;
import com.bstek.dorado.data.provider.Page;

import gov.pbc.nn.kjgl.entity.TrainingPlan;
import gov.pbc.nn.kjgl.entity.TrainingUser;
import gov.pbc.nn.kjgl.train.dao.TrainPlanDao;
import gov.pbc.nn.kjgl.train.dao.TrainRegisterJdbcDao;

@Component
public class TrainPlanPR {

	@Autowired
	private TrainPlanDao trainPlanDao;

	@Autowired 
	private TrainRegisterJdbcDao trainRegisterJdbcDao;
	
	@DataProvider
	public void getAll(Page<TrainingPlan> page , Criteria criteria) {
		this.trainRegisterJdbcDao.getTrainingPlan(page,criteria);
	}

	@DataProvider
	public List<Map<String, Object>> getAssessor() {
		return trainPlanDao.getAssessor();
	}

	@Transactional
	@DataResolver
	public void saveAll(List<TrainingPlan> list) {
		trainPlanDao.save(list);
	}

	@Transactional
	@DataResolver
	public void TrainPlanTJ(List<TrainingPlan> list) {
		trainPlanDao.TrainPlanTJ(list);
	}

	@Expose
	@Transactional
	public void updateState(List<String> ids, int revoke) {
		if (revoke == 2) {
			for (String id : ids) {
				trainPlanDao.updateStateTj(id);
			}
		} else {
			for (String id : ids) {
				trainPlanDao.updateStateRem(id);
			}
		}
	}

	@Expose
	@Transactional
	public void delete(List<String> ids) {
		for (String id : ids) {
			trainPlanDao.delete(id);
		}
	}

	@Transactional
	@Expose
	public void releaseMeeting(Map<String, Object> parameter) throws ParseException {
		trainPlanDao.releaseMeeting(parameter);
	}
	
	@Transactional
	@Expose
	public void  finish(String id) {
		trainPlanDao.finish(id);
	}

}
